﻿using D3StatsClient.Model;
using D3StatsClient.ViewModel;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D3StatsClient.Commands
{
    public class BrowseForSoundFile : CommandBase
    {
        public BrowseForSoundFile()
        {
        }

        public override bool CanExecute(object parameter)
        {
            return true;
        }

        public override void Execute(object parameter)
        {
            var vm = ViewModelManager<SettingsWindowsViewModel>.ViewModel;

            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog.Filter = "Sound Files (.wave)|*.wav";
            openFileDialog.FilterIndex = 1;

            openFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "Sounds";

            openFileDialog.Multiselect = false;

            // Call the ShowDialog method to show the dialog box.
            bool? userClickedOK = openFileDialog.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                //Get the filename from the dialog to put in the label
                //Get the full path to put in the settings.

                switch (parameter.ToString())
                {
                    case "LegendarySoundFile":
                        vm.LegendarySoundFile = openFileDialog.FileName;
                        break;
                    case "RareSoundFile":
                        vm.RareSoundFile = openFileDialog.FileName;
                        break;
                    case "MagicSoundFile":
                        vm.MagicSoundFile = openFileDialog.FileName;
                        break;
                    case "CraftingSoundFile":
                        vm.CraftingSoundFile = openFileDialog.FileName;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
